#include <func.h>
#include "head.h"
//服务端接收客户端发来的文件
//结构体之后放到头文件里去

int upload(char* argv, char* pwd, int netFd){
    //puts file
    //pwd /usr1
    char arr[100] = "";
    strcpy(arr, argv);
    char* command = strtok(arr, " ");
    char* fileName = strtok(NULL, " ");
    char filePath[100] = {0};
    sprintf(filePath, ".%s%s%s", pwd, "/", fileName);
    //得到文件大小
    int dataLength;
    long fileSize;
    recvn(netFd, &dataLength, sizeof(int));
    recvn(netFd, &fileSize, dataLength);
    printf("filesize = %lu\n", fileSize);
    int fd = open(filePath, O_RDWR|O_CREAT, 0666);
    ERROR_CHECK(fd, -1, "open");
    ftruncate(fd, fileSize);
    char *p = (char *)mmap(NULL, fileSize, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
    recvn(netFd, p, fileSize);
    munmap(p, fileSize);
    close(fd);
}